<%@ page contentType="text/html; charset=utf-8"%>
<%@ include file="/global/jsp-header.jsp"%>
<!DOCTYPE HTML>
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html">
		<title>新增部门</title>
		<%@ include file="/global/html-header.jsp"%>
		<script>
	$(function() {
		$('.myform').idealforms();
		common.validator("roleform");
		//添加部门
		$("#roleform").submit(function(){
			var param=$(this).serialize();
			var canSubmit=common.checkBlankValue(param,new Array("role.roleName","role.orderNo"));
			if(canSubmit){
				$.ajax({   
	        		type: "POST",  
	        		url: "${action }",  
	        		data: param, 
	        		success: function(msg){    
		        		window.parent.closeDialog();
		        		var alertMsg="";
	        			<c:if test="${addOperater}">
		        			if(msg=="success"){
	            				alertMsg="角色添加成功！";
	            				$(window.parent.document).find("#myform").submit();
	            			}else if(msg=="exists"){
	            				alertMsg="角色已存在！";
	            			}else{
	            				alertMsg="角色添加失败！";
	            			}
	        			</c:if>
	        			<c:if test="${updateOperater}">
		        			if(msg=="success"){
		        				var htm='<td>item.roleId</td><td>item.roleName</td><td>item.orderNo</td><td>'+
		    	            	'<a href="#" onclick="editRole(item.roleId)">编辑</a><a href="#" onclick="deleteRole(item.roleId)">删除</a></td>';
		    	            	var rlId=common.getValueByFieldName(param,"role.roleId");
		    	            	var rlName=common.getValueByFieldName(param,"role.roleName");
		    	            	var rlOrderNo=common.getValueByFieldName(param,"role.orderNo");
		    	            	htm=htm.replace(/item.roleId/gi,rlId).replace(/item.roleName/gi,decodeURI(rlName)).replace(/item.orderNo/gi,rlOrderNo);
		    	            	$(window.parent.document).find("#queryResultIframe").contents().find("tr[roleId="+rlId+"]").html(htm);
		    	            	$(window.parent.document).find("#queryResultIframe").contents().find("tr[roleId="+rlId+"]").attr("roleId",rlId);
		        				alertMsg="角色更新成功！";
	            			}else if(msg=="nochange"){
	            				alertMsg="角色属性没有改变！";
	            			}else{
	            				alertMsg="角色更新失败！";
	            			}
        				</c:if>
        				window.parent.editRoleTip(alertMsg);
	        		} 
	        	});
			}
			return false;
		});
	});
</script>
	</head>
	<body>
		<form action="${action }" name="roleform" class="myform"
			id="roleform" method="post">
			<input type="hidden" size="40" name="role.roleId" value="${role.roleId }"/>
			<div>
				<label class="required">
					角色名称:
				</label>
				<input type="text" size="40" name="role.roleName"  value="${role.roleName }" class="{required:true,messages:{required:'请输入角色名称'}}" />
			</div>
			<div>
				<label class="required">
					角色优先级:
				</label>
				<input type="text" size="40" name="role.orderNo" value="${role.orderNo }"
					class="{required:true,digits:true,messages:{required:'请输入角色优先级'}}" />
			</div>
			<div>
				<label>
					&nbsp;
				</label>
				<input type="submit" value="${btnKeyWord }" />
			</div>
		</form>
	</body>
</html>